<!-- Merge home and current page translations -->
{{ $bookTranslatedOnly := default false .Site.Params.BookTranslatedOnly }}
{{ $translations := dict }}
{{ if (eq $bookTranslatedOnly false ) }}
  {{ range .Site.Home.Translations }}
    {{ $translations = merge $translations (dict .Language.Lang .) }}
  {{ end }}
{{ end }}
{{ range .Translations }}
  {{ $translations = merge $translations (dict .Language.Lang .) }}
{{ end }}

<ul class="book-languages">
  <li>
    <input type="checkbox" id="languages" class="toggle" />
    <label for="languages" class="flex">
      <a role="button" class="flex flex-auto">
        <img src="{{ "svg/translate.svg" | relURL }}" class="book-icon" alt="Languages" />
        <span>{{ $.Site.Language.LanguageName }}</span>
      </a>
    </label>

    <ul>
      {{ range .Site.Languages }}{{ with index $translations .Lang }}
      <li>
        <a href="{{ cond hugo.IsMultihost .Permalink .RelPermalink }}">
          <span>{{ .Language.LanguageName }}</span>
        </a>
      </li>
      {{ end }}{{ end }}
    </ul>
  </li>
</ul>
